Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to retry a data provider during failures #2820

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

krmahadevan
Copy link
Member

Closes #2819

Fixes #2819 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

Sample test case

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestClassUsingDataProviderRetrySample {

  private int counter = 0;

  @Test(dataProvider = "dp")
  public void sampleTest(int ignored) {}

  @DataProvider(name = "dp", retryUsing = SimpleRetry.class)
  public Object[][] getTestData() {
    if (counter++ < 2) {
      throw new RuntimeException("Simulating a failure");
    }
    return new Object[][] {{1}};
  }
}

Sample retry mechanism implementation

import org.testng.IDataProviderMethod;
import org.testng.IRetryDataProvider;

public class SimpleRetry implements IRetryDataProvider {

  private int counter = 0;

  @Override
  public boolean retry(IDataProviderMethod dataProvider) {
    return counter++ < 2;
  }
}

@krmahadevan krmahadevan merged commit f3bc377 into testng-team:master Nov 3, 2022
@krmahadevan krmahadevan deleted the fix_2819 branch November 3, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to retry a data provider in case of failures
2 participants